import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

import { getUserListURL } from '../../app/someConst';

import {Http, Headers, RequestOptions} from '@angular/http';

import { People } from '../../app/people';

/**
 * Generated class for the PeopleListPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@Component({
  selector: 'page-people-list',
  templateUrl: 'people-list.html',
})
export class PeopleListPage {

  userArray: Array<People>;

  constructor(public navCtrl: NavController, 
              public navParams: NavParams,
              public http: Http) {

                this.requestForUserList();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PeopleListPage');
  }

  requestForUserList(){
    let body = new FormData();
    this.http.post(getUserListURL,body).map(res => res.json()).subscribe(
      data => {
        console.log(data);
        let array = data.result as Array<People>

        this.userArray = array;

        // for (var p in array) {
        //   if (object.hasOwnProperty(key)) {
        //     var element = object[key];
            
        //   }
        // }
      },
      err => {

      }
    )


  }

  itemSelected(people){
    alert(people.user_name);
  }


}
